<?php

require_once(dirname(__FILE__) . '/appconf.php');

class Gurl extends Site {

    function setup() {
        $this->run_modes('get_url','get_eurl');
        $this->start_mode('get_url');
        parent::setup();
    }

    function cgiapp_prerun($rm = '') {
        parent::cgiapp_prerun();
    }

    function action_get_url() {
        $pid = intval($this->get_q('pid', 0, 'int'));
        $str = "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>";
        $str .= "請填寫需要Preview的產品ID：<br/>";
        $str .= "<form action='/gurl.php?action=get_url' method='post'>";
        $str .= "<input type='text' name='pid' value=''/><input type='submit' value='提交'/>";
        $str .= "</form>";
        $md5_pid = md5($pid . 'imoreHK');
        $global_url = $this->param('URL');
        if (!empty($pid)) {
            $str .= "<br/><a target='_blank' href=\"" . $global_url . "product.php?action=invite_page&pid=" . $pid . "&m=" . $md5_pid . "\">" . $global_url . "product.php?action=invite_page&pid=" . $pid . "&m=" . $md5_pid . "</a>";
            $str .= "<br/>";
            $str .= "<br/><a target='_blank' href=\"http://itrial.hk/product.php?action=invite_page&pid=" . $pid . "&m=" . $md5_pid . "\">http://itrial.hk/product.php?action=invite_page&pid=" . $pid . "&m=" . $md5_pid . "</a>";
        }
        echo $str;
    }

    function action_get_eurl() {
        $eid = intval($this->get_q('eid', 0, 'int'));
        $str = "<meta http-equiv='Content-Type' content='text/html; charset=UTF-8'>";
        $str .= "請填寫需要Preview的活動ID：<br/>";
        $str .= "<form action='/gurl.php?action=get_eurl' method='post'>";
        $str .= "<input type='text' name='eid' value=''/><input type='submit' value='提交'/>";
        $str .= "</form>";
        $md5_eid = md5($eid . 'imoreHK');
        $global_url = $this->param('URL');
        if (!empty($eid)) {
            $str .= "<br/><a target='_blank' href=\"" . $global_url . "event.php?action=invite_page&eid=" . $eid . "&m=" . $md5_eid . "\">" . $global_url . "event.php?action=invite_page&eid=" . $eid . "&m=" . $md5_eid . "</a>";
            $str .= "<br/>";
            $str .= "<br/><a target='_blank' href=\"http://itrial.hk/event.php?action=invite_page&eid=" . $eid . "&m=" . $md5_eid . "\">http://itrial.hk/event.php?action=invite_page&eid=" . $eid . "&m=" . $md5_eid . "</a>";
        }
        echo $str;
    }

}

$webapp = new Gurl();
$webapp->run();
?>